package org.wang.generalcode.modules.gen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wang.generalcode.modules.gen.pojo.entity.GenBaseClass;
import org.wang.generalcode.modules.gen.service.BaseClassService;
import org.wang.generalcode.support.mybaties.Condition;
import org.wang.generalcode.support.mybaties.Query;
import org.wang.generalcode.support.result.Result;
import org.wang.generalcode.support.utils.Func;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/baseclass")
@Schema(description = "基类管理", name = "基类管理接口")
public class BaseClassController {

    private final BaseClassService baseClassService;

    @ApiOperationSupport(order = 1)
    @Schema(description = "分页查询", example = "传入query")
    @GetMapping("/page")
    public Result<IPage<GenBaseClass>> page(Query query) {
        IPage<GenBaseClass> page = baseClassService.page(Condition.getPage(query));
        return Result.success(page);
    }

    @ApiOperationSupport(order = 2)
    @Schema(description = "列表查询", example = "")
    @GetMapping("/list")
    public Result<List<GenBaseClass>> list() {
        List<GenBaseClass> list = baseClassService.list();
        return Result.success(list);
    }

    @ApiOperationSupport(order = 3)
    @Schema(description = "查询详情", example = "")
    @GetMapping("/detail")
    public Result<GenBaseClass> get(@Parameter(name = "主键", required = true) @RequestParam Long id) {
        GenBaseClass data = baseClassService.getById(id);
        return Result.success(data);
    }

    @ApiOperationSupport(order = 5)
    @Schema(description = "保存", example = "")
    @PostMapping("/save")
    public Result<String> save(@RequestBody GenBaseClass entity) {
        return Result.judge(baseClassService.save(entity));
    }

    @ApiOperationSupport(order = 6)
    @Schema(description = "修改", example = "")
    @PostMapping("/update")
    public Result<String> update(@RequestBody GenBaseClass entity) {
        return Result.judge(baseClassService.updateById(entity));
    }

    @PostMapping("/remove")
    @ApiOperationSupport(order = 7)
    @Schema(description = "删除", example = "传入ids")
    public Result<String> remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
        return Result.judge(baseClassService.removeBatchByIds(Func.toLongList(ids)));
    }
}
